<?php
class blogComponents extends sfComponents {
    public function executeCal(sfRequest $request) {
        $date = VanillaPostPeer::getYears();

        $anni = array();
        $mesi = array();

        foreach($date as $data) {
            $unique = true;
            foreach($anni as $anno) {
                if($data['anno'] == $anno)
                    $unique = false;
            }

            if($unique)
                $anni[] = $data['anno'];
        }

        $oggi = date("Y");
        $active = "";

        foreach($anni as $key => $anno) {
            $mesi[$key] = array(
            '01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0,
            '07' => 0, '08' => 0, '09' => 0, '10' => 0, '11' => 0, '12' => 0
            );

            if($anno == $oggi)
                $active = $key;

            foreach($date as $data) {
                if($data['anno'] == $anno) {
                    $mesi[$key][$data['mese']]++;
                }
            }
        }


        $this->anni = $anni;
        $this->mesi = $mesi;
        $this->active = $active;
    }

    public function executeLatestPost() {
        $this->post = VanillaPostPeer::getLatestPost();
    }
}
?>